package com.woniuxy.cloud.userassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.cloud.entity.TUserBlack;

import com.woniuxy.cloud.form.AddUserBlackForm;
import com.woniuxy.cloud.userassembly.mapper.TUserBlackMapper;
import com.woniuxy.cloud.userassembly.service.ITUserBlackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 用户黑名单表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-09-30
 */
@Service
@Slf4j
public class TUserBlackServiceImpl extends ServiceImpl<TUserBlackMapper, TUserBlack> implements ITUserBlackService {


    /**
     * 冻结用户
     * @param addUserBlackForm
     * @return Integer
     */
    @Override
    public Integer addUserBlack(AddUserBlackForm addUserBlackForm) {
        TUserBlack tUserBlack = new TUserBlack();
       tUserBlack.setUserBlackUserId(addUserBlackForm.getUserId()).setUserBlackJoinTime(new Date()).setUserBlackStatus(addUserBlackForm.getUserBlackStatus()).setUserBlackReason(addUserBlackForm.getUserBlackReason());
        return getBaseMapper().insert(tUserBlack);
    }

    /**
     * 查看用户是否冻结
     * @param userId 用户id
     * @return
     */
    @Override
    public TUserBlack getUserBlackByUserId(Integer userId) {
        QueryWrapper<TUserBlack> wrapper = new QueryWrapper<>();
          wrapper.eq("user_black_user_id",userId);
        TUserBlack tUserBlack = getBaseMapper().selectOne(wrapper);
        return getBaseMapper().selectOne(wrapper);
    }
}
